//
//  YHBZDStore.m
//  HBDemo
//
//  Created by RYX on 2019/3/26.
//  Copyright © 2019 tuobu. All rights reserved.
//

#import "YHBZDStore.h"
#import "YHBZDNameModel.h"
#import "YHBZDSNModel.h"
#import "TZJEDataModel.h"

@implementation YHBZDStore

#pragma mark - 已划拨终端（分组统计）
- (void)getYHBZDNameListWithCustomerId:(NSString *)customerId Success:(void(^)(NSArray *listArr))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/instance/flow",IP];
    
    NSDictionary *dic = @{
                          @"customerId":customerId
                          };
    
    [HttpTool getUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            
            NSArray *listArr = [YHBZDNameModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
            success(listArr);
        }else{
            
            failure(error);
        }
    } failure:^(NSError *error) {
       
        failure(error);
    }];
}

#pragma mark - 已划拨终端（列表）
- (void)getYHBZDSNListWithCustomerId:(NSString *)customerId current:(NSString *)current size:(NSString *)size targetId:(NSString *)targetId Success:(void(^)(NSArray *listArr))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/instance/flow/%@",IP,targetId];
    
    NSDictionary *dic = @{
                          @"customerId":customerId,
                          @"current":current,
                          @"size":size,
                          };
    
    [HttpTool getUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            
            NSArray *listArr = [YHBZDSNModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"records"]];
            success(listArr);
        }else{
            
            failure(error);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

#pragma mark - 获取调整返现页面数据
- (void)getTXDataWithSn:(NSString *)sn Success:(void(^)(TZJEDataModel *model))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/flow/reset/%@",IP,sn];

    [HttpTool getUrlWithString:url parameters:nil success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            
            TZJEDataModel *model = [TZJEDataModel mj_objectWithKeyValues:responseObject[@"data"]];
            success(model);
        }else{
            
            failure(error);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

#pragma mark - 申请重设返现金额
- (void)putfxjeWithSn:(NSString *)sn andAmount:(NSString *)amount Success:(void(^)(void))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/flow/reset/amount",IP];
    
    NSDictionary *dic = @{
                          @"amount":amount,
                          @"sn":sn
                          };
    
    [HttpTool putUrlWithString:url parameters:dic success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
        
            success();
        }else{
            
            failure(error);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}
@end
